import { request } from "../../request/http.js"

Page({
  data:{
    userInfo:''
  },

  getUserProfile(e) {
    wx.getUserProfile({
      desc: '用于完善会员资料', 
      success: (res) => {
        console.log('用户信息',res);
           wx.setStorageSync('userinfo', res.userInfo)
           //加密信息解构出来
          let {encryptedData,iv,rawData,signature}=res
          wx.login({
            success (res1) {
              console.log('登录成功code码',res1);
              let code=res1.code
              if (res1.code) {
             
                  request({url:'users/wxlogin',data:{encryptedData,iv,rawData,signature,code},method:'post'}).then(res2=>{
                       console.log('获取token成功',res2);
                       wx.setStorageSync('token', 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo')
                    
                       wx.navigateBack({
                         delta: 1,  
                       })
                  })
              } else {
                    console.log('登录失败！' + res.errMsg)
              }
            }
          })

      },
      fail:(err)=>{
        console.log('失败',err);
      }
    })
  },
  
})